<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<script type="text/javascript">
	$(function(){
		$("#writeQnA").click(function(){
			 var flag=confirm("QnA를 작성하시겠습니까?");
			   if(flag){
				  location.href="board.do?command=qnaWrite&m_id="+'${sessionScope.loginMember.mvoLogin.m_id}';
			   }
		});
		 $("#goSearchButton").click(function(){
			   if($("#searchQnaSelect").val()==""){
				   alert("검색조건을 선택하세요");
				   return;
			   }else if($("#searchQnaText").val()==""){
				   alert("검색조건을 입력하세요");
				   return;
			   }
			   location.href="board.do?command=searchQna&searchQnaSelect="+
					   $("#searchQnaSelect").val()+"&searchQnaText="+$("#searchQnaText").val();
		   });
				$("#deleteContent").click(function(){
					var flag=confirm("선택된 게시물을 삭제하시겠습니까?");
					if($("#qnaListForm :radio[name=delContent]:checked").length==0){
						alert("삭제할 게시물을선택하세요");
						return; 	
					}else if(flag){
					location.href="board.do?command=deleteContentByAdmin&b_no="+ $(':input:radio[name=delContent]:checked').val();
					}   
		 });
	
	});
	
</script>
<link rel="stylesheet" href="${initParam.root }/css/board/main_boardList.css">
<form action="${initParam.root }/board.do" method="post" id="qnaListForm" name="qnaForm">
<div id="전체틀">
<header>
	<h2>
		<img src="${initParam.root }/img/bbom&search/main-bbom-main.gif"
			alt="RapidXHTML" />
	</h2>
</header>
	<div id="board">
		<table id="head">
			<tr><c:if test="${sessionScope.loginMember.mvoLogin.m_type=='a'}">
				<td align="center"width="5%">선택</td></c:if><td width="10%" class="main_td">글번호</td><td width="50%">제목</td><td width="15%">작성자</td><td width="15%">작성일</td><td width="10%">조회</td>
		</table>
		<c:if test="${requestScope.searchQnaList.list!='null' }">
		<table id="body">
			<c:forEach items="${requestScope.searchQnaList.list }" var="qnaList" varStatus="i">
					<c:choose>
				<c:when test="${i.count%5==0}">
					<tr class="tr_line"> 
				</c:when>
				<c:otherwise>
					<tr class="tr_noline">		
				</c:otherwise>
			</c:choose>
			<c:if test="${sessionScope.loginMember.mvoLogin.m_type=='a'}">
			<td align="center" width="5%">
			<input type="radio" name="delContent" value="${qnaList.b_no}" id="b_no" ></td>
			</c:if>
				<td width="10%">${qnaList.b_no}</td>
				<%-- bvo에 relevel이 0이 아니면 답변글이므로 relevel만큼 공백으로 제목을 밀어준다  --%>
				<td width="50%" class="tr_title">
				<c:if test="${qnaList.b_relevel!=0}">
					<c:forEach begin="0" end="${qnaList.b_relevel}" step="1">&nbsp;&nbsp;&nbsp;</c:forEach>
					<img src="${initParam.root }/img/paging/reply.jpg">
					</c:if>
				<a href="${initParam.root }/board.do?command=showContent&bno=${qnaList.b_no }
				&pageNo=${requestScope.searchQnaList.pagingBean.nowPage}&mid=${qnaList.m_id}" name="showCon">${qnaList.b_title}</a>
				<c:if test="${qnaList.newfilename!=null }">
						<a href="${initParam.root}/board.do?command=fileDownload&newfilename=${qnaList.newfilename }
						&orgfilename=${qnaList.orgfilename }">
							<img alt="#" src="${initParam.root }/img/paging/main-board-file.gif">
						</a>
					</c:if>
					<c:if test="${qnaList.totalReply!=0 }">
						[${qnaList.totalReply }]
					</c:if>
					<c:if test="${requestScope.map.today==qnaList.b_date}">
							<img alt="#" src="${initParam.root }/img/paging/main-board-new.gif">
					</c:if>
				</td>
				<td width="15%" class="td_name">${qnaList.b_writer}</td>
				<td width="15%" class="td_date">${qnaList.b_date}</td>
				<td width="10%">${qnaList.b_cnt}</td>
			</tr>
			</c:forEach>
		</table>
	</c:if>
		<!-- 로그인 타입이 관리자이면 삭제버튼 보여주기-->
		<c:if test="${sessionScope.loginMember.mvoLogin.m_type=='a'}">
		<img alt="게시글삭제" src="${initParam.root }/img/paging/delete_btn.jpg" id="deleteContent">
		</c:if>  
		<!-- 로그인 되어있으면 글쓰기 버튼 보여주기 
		<a href="${initParam.root }/board/main_qnaWrite.jsp">-->
		<c:if test="${sessionScope.loginMember!=null }">
			<div id="write">
				<img alt="글쓰기" src="${initParam.root }/img/paging/write_btn.jpg" id="writeQnA"></a>
			</div>
		</c:if>
		
	<!-- 페이징 처리  searchQnaText searchQnaSelect-->
	<div align="center"><br>
	 <c:if test="${requestScope.searchQnaList.pagingBean.previousPageGroup }">
	 <a href= "${initParam.root }/board.do?command=searchQna&pageNo=${requestScope.searchQnaList.pagingBean.startPageOfPageGroup-1}&searchQnaSelect=${requestScope.searchQnaList.map.searchQnaSelect}&searchQnaText=${requestScope.searchQnaList.map.searchQnaText}">
	 <img src="${initParam.root }/img/paging/left_arrow_btn.gif"></a>
	 </c:if>
	<c:forEach var="i" 	
	begin="${requestScope.searchQnaList.pagingBean.startPageOfPageGroup}"
	 end="${requestScope.searchQnaList.pagingBean.endPageOfPageGroup}">
	 <c:choose>
	 <c:when test="${requestScope.searchQnaList.pagingBean.nowPage!=i}">
	 <a href="${initParam.root }/board.do?command=searchQna&pageNo=${i}&searchQnaSelect=${requestScope.searchQnaList.map.searchQnaSelect}&searchQnaText=${requestScope.searchQnaList.map.searchQnaText}">${i}</a>
	 </c:when>
	 <c:otherwise>
	${i}
	</c:otherwise>
	</c:choose>
	</c:forEach>	 
	 <c:if test="${requestScope.searchQnaList.pagingBean.nextPageGroup}">
	 <a href="${initParam.root }/board.do?command=searchQna&pageNo=${requestScope.searchQnaList.pagingBean.endPageOfPageGroup+1}&searchQnaSelect=${requestScope.searchQnaList.map.searchQnaSelect}&searchQnaText=${requestScope.searchQnaList.map.searchQnaText}">
	
	
	
	 <img src="${initParam.root }/img/paging/right_arrow_btn.gif"></a>
	 </c:if>	 
		</div><br> <br>	
	<!-- 검색 -->
	<div id="search" align="center">
	<select id="searchQnaSelect">
	<option value="">선택하세요</option>
	<option value="b_title">제목</option>
	<option value="b_writer">작성자</option>
	<option value="b_title&b_content">제목+내용</option>
	</select>
    <input type="text" id="searchQnaText" >
    <input type="button" name="searchButton" id="goSearchButton" value="검색">
		
		
		</div>
	</div>
</div>
	</form>
	
	
	
	
	
	
	
	
	
	
	